//
//  MainViewController.swift
//  DynamicColorDemo
//
//  Created by 李煜 on 2023/3/10.
//

import DynamicColor
import UIKit

class MainViewController: UITableViewController {
  let contentTitles: [String] = [
    "usage",
    "dark & lighten",
    "Saturate, Desaturate & Grayscale",
    "Adjust-hue & Complement",
    "Tint & Shade",
    "invert",
    "mix",
    "gridents"
  ]
  override func viewDidLoad() {
    super.viewDidLoad()

    tableView.register(UINib(nibName: "TestTableViewCell", bundle: nil), forCellReuseIdentifier: TestTableViewCell.TestCellId)
  }

  // MARK: - Table view data source

  override func numberOfSections(in tableView: UITableView) -> Int {
    1
  }

  override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return contentTitles.count
  }

  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: TestTableViewCell.TestCellId) as? TestTableViewCell ?? .init(style: .default, reuseIdentifier: TestTableViewCell.TestCellId)
    cell.titleLb.text = contentTitles[indexPath.row]
    return cell
  }

  // MARK: - delegate

  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let colorsDict: [String: [DynamicColor]] = [
      "usge": [UIColor(hexString: "#3498db"),
               UIColor(hex: 0x3498db),
               DynamicColor(hexString: "3498db")],

      "dark&lighten": [
        DynamicColor(hexString: "#c0392b"),
        DynamicColor(hexString: "#c0392b").lighter(),
        DynamicColor(hexString: "#c0392b").darkened()
      ],
      "Saturate, Desaturate & Grayscale":
        [
          DynamicColor(hexString: "#c0392b"),
          DynamicColor(hexString: "#c0392b").saturated(),
          DynamicColor(hexString: "#c0392b").desaturated(),
          DynamicColor(hexString: "#c0392b").grayscaled()
        ],
      "Adjust-hue & Complement": [
        DynamicColor(hex: 0xc0392b),
        DynamicColor(hex: 0xc0392b).adjustedHue(amount: 45),
        DynamicColor(hex: 0xc0392b).complemented()
      ]
    ]

    let title = contentTitles[indexPath.row]
    if let colors = colorsDict[title] {
      let contentVC = ContentViewController()
      
    }
  }
}
